//
//  RBServiceOrderCell.m
//  zhongzhenglu
//
//  Created by XL on 2022/8/15.
//

#import "RBServiceOrderCell.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import <Masonry.h>
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RBPager.h"
#import "RanTool.h"

@interface RBServiceOrderCell()

@property(nonatomic, strong)UIView *containerView;

@property(nonatomic, strong)UIView *shopView;
@property(nonatomic, strong)UILabel *shopNameL;
@property(nonatomic, strong)UILabel *statusL;

@property(nonatomic, strong)UIView *actionView;
@property(nonatomic, strong)UILabel *actionStatusL;

@property(nonatomic, strong)RBCellModel *cellModel;

@end

@implementation RBServiceOrderCell

- (void)setCellModel:(RBCellModel *)cellModel
{
    _cellModel = cellModel;
    [self.containerView view_clear];
    [self.containerView view_addView:self.shopView withHeight:Zoom(43) width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
    [self.containerView view_addView:[self lineView] withHeight:1 width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(15) right:Zoom(15) centerX:0];
    NSInteger count = arc4random_uniform(2) + 1;
    for (NSInteger i = 0; i < count; i++)
    {
        [self.containerView view_addView:[self goodsViewWithData:nil] withHeight:Zoom(97) width:CGFLOAT_MIN top:Zoom(13) bottom:0 left:Zoom(0) right:Zoom(0) centerX:0];
    }
    [self.containerView view_addView:[self lineView] withHeight:1 width:CGFLOAT_MIN top:Zoom(13) bottom:0 left:Zoom(15) right:Zoom(15) centerX:0];
    [self.containerView view_addView:[self actionView] withHeight:Zoom(30) width:CGFLOAT_MIN top:Zoom(16) bottom:Zoom(12) left:0 right:0 centerX:0];
    
    if (arc4random_uniform(2))
    {
        self.statusL.text = @"售后";
        self.statusL.textColor = [UIColor colorWithHexString:@"#518CFF"];
        self.actionStatusL.text = nil;
    }
    else
    {
        self.statusL.text = @"退款";
        self.statusL.textColor = [UIColor colorWithHexString:@"#D11111"];
        self.actionStatusL.text = @"进度：退款中/退款成功/退款失败";
    }
}

#pragma mark - Event

- (void)checkDetailBtnTapped
{
    if (self.cellModel.eventBlock)
    {
        self.cellModel.eventBlock(self.cellModel.cellData);
    }
}

#pragma mark - Getter

- (UIView *)containerView
{
    if (!_containerView)
    {
        self.containerView = ({
            UIView *view = UIView.new;
            view.backgroundColor = UIColor.whiteColor;
            [view rbSetCornerRadius:Zoom(8)];
            [self.contentView addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(0);
                make.width.mas_equalTo(Zoom(350));
            }];
            view;
        });
    }
    return _containerView;
}

- (UIView *)shopView
{
    if (!_shopView)
    {
        self.shopView = ({
            UIView *view = UIView.new;
            
            UIImageView *shopImgView = [RanTool imgViewWithMode:1 radius:0 imgName:@"groupPayShop"];
            [view addSubview:shopImgView];
            [shopImgView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(Zoom(19));
                make.height.mas_equalTo(Zoom(17));
                make.left.mas_equalTo(Zoom(16));
                make.centerY.mas_equalTo(0);
            }];
            
            UILabel *shopNameL = [RanTool labelWithFontSize:Zoom(15) weight:1 color:[RBThemeConfig textBlackColor] align:0 text:@"店铺名称"];
            self.shopNameL = shopNameL;
            [view addSubview:shopNameL];
            [shopNameL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.mas_equalTo(0);
                make.width.mas_equalTo(Zoom(160));
                make.left.mas_equalTo(shopImgView.mas_right).offset(Zoom(11));
            }];
            
            UILabel *statusL = [RanTool labelWithFontSize:Zoom(14) weight:2 color:UIColor.blackColor align:0 text:@"status"];
            self.statusL = statusL;
            [view addSubview:statusL];
            [statusL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-Zoom(12));
                make.centerY.mas_equalTo(0);
            }];
            
            view;
        });
    }
    return _shopView;
}

- (UIView *)lineView
{
    UIView *view = UIView.new;
    view.backgroundColor = [RBThemeConfig lineGrayColor];
    return view;
}

- (UIView *)goodsViewWithData: (id)data
{
    UIView *view = UIView.new;
    
    UIImageView *imgView = [RanTool imgViewWithMode:2 radius:Zoom(5) imgName:@"b1.jpg"];
    [view addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(Zoom(15));
        make.top.mas_equalTo(0);
        make.width.height.mas_equalTo(Zoom(97));
    }];
    
    UILabel *nameL = [RanTool labelWithFontSize:Zoom(14) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:@"沪鸽凯晶塑钢牙科专用镜配套镜塑钢牙科专用镜配套镜塑钢牙科专用镜配套镜"];
    nameL.numberOfLines = 2;
    [view addSubview:nameL];
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imgView.mas_right).offset(Zoom(20));
        make.top.mas_equalTo(0);
        make.right.mas_equalTo(-Zoom(15));
    }];
    
    UILabel *countL = [RanTool labelWithFontSize:Zoom(12) weight:0 color:[RBThemeConfig textGrayColor] align:2 text:@"×1"];
    [countL setContentHuggingPriority:UILayoutPriorityDefaultHigh + 1 forAxis:UILayoutConstraintAxisHorizontal];
    [countL setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh + 1 forAxis:UILayoutConstraintAxisHorizontal];
    [view addSubview:countL];
    [countL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(nameL);
        make.top.mas_equalTo(nameL.mas_bottom).offset(Zoom(14));
        
    }];
    
    UILabel *paramL = [RanTool labelWithFontSize:Zoom(12) weight:0 color:[RBThemeConfig textGrayColor] align:0 text:@"属性文字"];
    [view addSubview:paramL];
    [paramL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(countL);
        make.left.mas_equalTo(nameL);
        make.right.mas_equalTo(countL.mas_left).offset(-Zoom(12));
    }];
    
    UILabel *priceL = UILabel.new;
    [view addSubview:priceL];
    [priceL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nameL);
        make.top.mas_equalTo(countL.mas_bottom).offset(Zoom(12));
    }];
    priceL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(12)] color:[RBThemeConfig textBlackColor] string:@"实付 "];
        [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(11)] color:[RBThemeConfig priceRedColor] string:@"¥"];
        [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(15)] color:[RBThemeConfig priceRedColor] string:@"400.00"];
    }];
    
    return view;
}

- (UIView *)actionView
{
    if (!_actionView)
    {
        self.actionView = ({
            UIView *view = UIView.new;
            
            self.actionStatusL = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:@"进度：退款中/退款成功/退款失败"];
            [view addSubview:self.actionStatusL];
            [self.actionStatusL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(Zoom(16));
                make.centerY.mas_equalTo(0);
            }];
            
            UILabel *checkL = [RanTool labelWithFontSize:Zoom(13) weight:0 color:UIColor.whiteColor align:1 text:@"查看详情" bgColor:[RBThemeConfig buttonBlueColor] radius:Zoom(15)];
            [checkL rbAddTapGesWithTarget:self action:@selector(checkDetailBtnTapped)];
            [view addSubview:checkL];
            [checkL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-Zoom(16));
                make.centerY.mas_equalTo(0);
                make.height.mas_equalTo(Zoom(30));
                make.width.mas_equalTo(Zoom(75));
            }];
            
            view;
        });
    }
    return _actionView;
}

@end
